package org.example.smallprojects.demos.web;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;

import javax.servlet.http.HttpSession;
@RestController
@RequestMapping("/user")
public class LoginController {
    @RequestMapping("/login")
    public Boolean login(String userName, String password, HttpSession session) {
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)) {
            return false;
        }
        if("遇事问春风乄".equals(userName)&&"666666".equals(password)) {
            //密码验证成功, 把⽤⼾名存储在Session中
            session.setAttribute("userName",userName);
            return true;
        }
        return false;
    }
    @RequestMapping("getLoginUser")
    public String getLoginUser(@SessionAttribute(value = "userName",required = false) String username) {
        return username;
    }
}
